package com.locationtracker.plus.app.weight.recyclerview.decoration;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

public class HorizontalSpacingItemDecoration extends RecyclerView.ItemDecoration {

    private final int spacing;
    private final int spacingCenter;

    public HorizontalSpacingItemDecoration(int spacing, int spacingCenter) {
        this.spacing = spacing;
        this.spacingCenter = spacingCenter;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        int total = parent.getAdapter().getItemCount();
        int position = parent.getChildAdapterPosition(view);
        outRect.left = spacingCenter / 2;
        outRect.right = spacingCenter / 2;
        if (position == 0) {
            outRect.left = spacing;
        }
        if (total == (position + 1)) {
            outRect.right = spacing;
        }
    }
}